cmake_minimum_required(VERSION 3.5.0)
project(trajopt VERSION 0.1.0 LANGUAGES CXX)

find_package(Eigen3 REQUIRED)
find_package(Boost COMPONENTS system thread program_options REQUIRED)
find_package(console_bridge REQUIRED)
find_package(trajopt_sco REQUIRED)
find_package(trajopt_utils REQUIRED)
find_package(tesseract REQUIRED)
find_package(tesseract_visualization REQUIRED)
find_package(jsoncpp REQUIRED)

link_directories(
    /usr/local/lib
    /usr/local/lib64
)

set(TRAJOPT_SOURCE_FILES
    src/trajectory_costs.cpp
    src/kinematic_terms.cpp
    src/collision_terms.cpp
    src/json_marshal.cpp
    src/problem_description.cpp
    src/utils.cpp
    src/plot_callback.cpp
    src/file_write_callback.cpp
)

add_library(${PROJECT_NAME} SHARED ${TRAJOPT_SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC
    trajopt::trajopt_sco
    trajopt::trajopt_utils
    tesseract::tesseract
    tesseract::tesseract_visualization
    console_bridge
    ${Boost_SYSTEM_LIBRARY}
    jsoncpp_lib)
trajopt_target_compile_options(${PROJECT_NAME} PUBLIC)
trajopt_clang_tidy(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
    "$<INSTALL_INTERFACE:include>")
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
    ${EIGEN3_INCLUDE_DIRS}
    ${Boost_INCLUDE_DIRS})

trajopt_configure_package(${PROJECT_NAME})

# Install test data directory for use in other packages
add_library(${PROJECT_NAME}_test_data INTERFACE)
target_link_libraries(${PROJECT_NAME}_test_data INTERFACE)
target_compile_definitions(${PROJECT_NAME}_test_data INTERFACE TRAJOPT_DIR="${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")

trajopt_target_compile_options(${PROJECT_NAME}_test_data INTERFACE)
trajopt_configure_package(${PROJECT_NAME}_test_data)

foreach(dir test/data)
   install(DIRECTORY ${dir}/
      DESTINATION share/${PROJECT_NAME}/${dir})
endforeach()


# Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}
  DESTINATION include
  FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "*.hxx"
  PATTERN ".svn" EXCLUDE
 )

if (TRAJOPT_ENABLE_TESTING)
  enable_testing()
  trajopt_add_run_tests_target()
  add_subdirectory(test)
endif()

if (TRAJOPT_ENABLE_BENCHMARKING)
  add_subdirectory(test/benchmarks)
endif()

